<?php
/* 
* @Author: Jerry-chen
* @Date:   2014-07-07 14:10:24
* @Last Modified time: 2014-07-23 17:09:02
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/
class MemberControl extends CommonControl
{
	
	public function index()
	{
		// p($_GET);
		//根据订单号查出同一订单的商品，然后分配数据
		$orderdata = K('Order')->get_all(array('uid'=>session('uid')));
		$count = 0;
		foreach ($orderdata as $k => $v) {
			$orderlist = K('Orderlist')->get_all(array('orderid'=>$v['orderid']),array('timeid','goodsid','price','number','recount'));
			// p($orderlist);

			$orderdata[$k]['orderlist'] = $orderlist;
				foreach ($orderlist as $key => $value) {
					// 根据时间ID，查出时间
				$timename = K('Goodstime')->get_one(array('timeid'=>$value['timeid']),array('time'));
				$orderdata[$k]['orderlist'][$key]['time'] = $timename['time'];
				//根据货品ID查出货物名
				$goodsname = K('Goods')->get_one(array('goodsid'=>$value['goodsid']),array('goodsname'));
				$orderdata[$k]['orderlist'][$key]['goodsname'] = $goodsname['goodsname'];
				//价格
				$orderdata[$k]['orderlist'][$key]['price'] = $value['price'];
				$orderdata[$k]['orderlist'][$key]['number'] = $value['number'];
				$orderdata[$k]['orderlist'][$key]['recount'] = $value['recount'];
				$count += $value['recount'];
				//订单合计
				}
				
		}
		// p($c/ount);
		//分配订单数据
		$this->assign('orderdata',$orderdata);
		$this->assign('count',$count);
		$this->display();
	}
	/**
	 * [orderlist 我的收藏]
	 * @return [type] [description]
	 */
	public function collect()
	{
		//查出当前用户的收藏
		$collectData = K('Collect')->get_all(array('uid'=>session('uid')));
		if(is_array($collectData)){
			// p($collectData);
			foreach ($collectData as $k => $v) {
			//商品信息
			$goodsinfo = K('Goods')->get_one(array('goodsid'=>$v['goodsid']),array('title','goodsname','startime','overtime','cinemaid'));
			$collectData[$k]['title'] = $goodsinfo['title'];
			$collectData[$k]['goodsname'] = $goodsinfo['goodsname'];
			$collectData[$k]['startime'] = $goodsinfo['startime'];
			$collectData[$k]['overtime'] = $goodsinfo['overtime'];
			//场馆地址
			$place = K('Cinema')->get_one(array('cinemaid'=>$goodsinfo['cinemaid']),'cinemaaddress');
			$collectData[$k]['place'] = $place['cinemaaddress'];
			//图片信息
			$goodspic = K('Goodsdes')->get_one(array('goodsid'=>$v['goodsid']),'goodsimage');
			$collectData[$k]['goodsimage'] = $goodspic['goodsimage'];
			
			}
		}else{
			$collectData=array();
		}
		
		$this->assign('collectData',$collectData);
		// p($collectData);
		$this->display('collection.html');

	}
	/**
	 * [del_collect 删除收藏内容]
	 * @return [type] [description]
	 */
	public function del_collect()
	{
		$result = K('Collect')->del_(array('goodsid'=>Q('get.goodsid')));
		if($result)
		{
			$this->success('删除成功','');
		}
	}
	/**
	 * [address 收货地址]
	 * @return [type] [description]
	 */
	public function address()
	{
		if(IS_POST)
		{
			// p(Q('post.'));
			$address = Q('post.province')."省".Q('post.city')."市".Q('post.county')."--".Q('post.addressfull');
			p($address);
			$data = array(
				'realname'=>Q('post.realname'),
				'address'=>$address,
				'code'=>Q('post.code'),
				'mbphonenumber'=>Q('post.mbphonenumber'),
				'phonenumber'=>Q('post.phonenumber'),
				'uid'=>session('uid'),
				'email'=>Q('post.email'),
				);
			$result = K('Spaddress')->add_($data);
			if($result)
			{
				$this->success('地址提交成功','');
			}
		}
		$addressData = K('Spaddress')->get_all(array('uid'=>session('uid')));
		// p($addressData);
		$this->assign('addressData',$addressData);
		$this->display();
	}
	/**
	 * [comfirm_ordre 确认收货]
	 * @return [type] [description]
	 */
	public function comfirm_ordre()
	{
		$data =array(
				'stadus'=>3,
				);
				$result = K('Order')->edit(array('orderid'=>Q('get.orderid')),$data);
				$this->success('确认成功','');	
	}
}


